#ifndef SCREENVIEW_H
#define SCREENVIEW_H
#include <QPainter>
#include <QWidget>
#include <QEvent>
#include <QGraphicsItem>
#include <QTimer>
#include <QObject>

class ScreenMode{
public:
	enum Enum{
		Middle_4_3,
		Middle_16_9,
		Right_4_3,
		Right_16_9,
		None_4_3,
		None_16_9
	};
};

class LedStripe{
public:
	QPoint start;
	QPoint end;
	double percent;
	int direction;

	LedStripe(){}
	LedStripe(int x1, int y1, int x2, int y2, double per, int dir){
		start.setX(x1); start.setY(y1);
		end.setX(x2); end.setY(y2);
		percent = per;
		direction = dir;
	}
};

class ScreenView : public QObject, public QGraphicsItem
{
	Q_OBJECT

	double _x0, _y0, _width, _height;
	QString _imageFile;
	double _ratio; // X/Y
	QRectF _frameSize;
	int _ledSize;
	QPixmap* _screen;
    int _screenNumber;
	int _xRatioPart;
	int _yRatioPart;

	QTimer _timer;

	bool _twin;
	bool _showImage;

    void updateView();

public:
	ScreenView(QObject* parent = 0);
	ScreenView(int x, int y, int width, int height, QObject* parent = 0);

	void setGeometry(int width, int height);

	void setMode(ScreenMode::Enum mode);


	QList<LedStripe> stripes();

    int getScreenNumber(){return _screenNumber;}
    void setScreenNumber(int num){_screenNumber=num;}
	void showScreenShots(bool show) { _showImage = show; }

	QRectF boundingRect() const;
	QPainterPath shape() const;
	void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

private slots:
	void onTimer();
};

#endif // SCREENVIEW_H
